package com.star.star.controller;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.star.security.annotations.Authorize;
import com.star.star.dto.*;
import com.star.star.service.StarChatService;
import com.star.star.vo.StarChatPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.star.core.base.BaseController;

/**
 * 粉丝留言艺人
 *
 * @author yangzj
 */
@RestController
@RequestMapping("/star-chat")
public class StarChatController extends BaseController {

    @Autowired
    private StarChatService starChatService;

    //-------------------- 以下通用接口 --------------------

    /**
     * 粉丝留言-通用
     *
     * @param dto 入参
     */
    @Authorize({"wxuser", "wxmentor"})
    @PostMapping("/initiate")
    public void initiate(@Validated @RequestBody StarChatInitiateSaveDTO dto) {
        starChatService.initiate(dto, getUserId());
    }

    /**
     * 艺人回复-通用
     *
     * @param dto 入参
     */
    @Authorize({"wxuser", "wxmentor"})
    @PostMapping("/replay")
    public void replay(@Validated @RequestBody StarChatReplaySaveDTO dto) {
        starChatService.replay(dto, getUserId());
    }

    /**
     * 分页后台管理查询（以艺人视角）
     *
     * @param dto 入参
     * @return {@link IPage}<{@link StarChatPageVO}>
     */
    @Authorize("star:chat:page")
    @PostMapping("/page")
    public IPage<StarChatPageVO> page(@Validated @RequestBody StarChatPageDTO dto) {
        Assert.notNull(dto.getUserId(), "艺人的用户ID不能为空");
        return starChatService.pageFans(dto.setUserId(getUserId()));
    }


    /**
     * 艺人回复时，粉丝名称列表分页-通用
     *
     * @param dto 入参
     * @return {@link IPage}<{@link StarChatPageVO}>
     */
    @Authorize({"wxuser", "wxmentor"})
    @PostMapping("/page-fans")
    public IPage<StarChatPageVO> pageFans(@Validated @RequestBody StarChatPageDTO dto) {
        return starChatService.pageFans(dto.setUserId(getUserId()));
    }

    /**
     * 粉丝留言时，艺人名称列表分页-通用
     *
     * @param dto 入参
     * @return {@link IPage}<{@link StarChatPageVO}>
     */
    @Authorize({"wxuser", "wxmentor"})
    @PostMapping("/page-star")
    public IPage<StarChatPageVO> pageStar(@Validated @RequestBody StarChatPageDTO dto) {
        return starChatService.pageStar(dto.setUserId(getUserId()));
    }

    /**
     * 艺人回复内容分页-通用
     *
     * @param dto 入参
     * @return {@link IPage}<{@link StarChatPageVO}>
     */
    @Authorize({"wxuser", "wxmentor"})
    @PostMapping("/page-replay")
    public IPage<StarChatPageVO> pageReplay(@Validated @RequestBody StarChatReplayPageDTO dto) {
        return starChatService.pageReplay(dto.setLoginUserId(getUserId()));
    }

    /**
     * 粉丝留言内容分页-通用
     *
     * @param dto 入参
     * @return {@link IPage}<{@link StarChatPageVO}>
     */
    @Authorize({"wxuser", "wxmentor"})
    @PostMapping("/page-initiate")
    public IPage<StarChatPageVO> pageInitiate(@Validated @RequestBody StarChatInitiatePageDTO dto) {
        return starChatService.pageInitiate(dto.setLoginUserId(getUserId()));
    }

}
